package com.luych.toolbox.docker.service.sdk.system;

import com.luych.toolbox.docker.service.sdk.system.model.*;
import org.springframework.web.client.RestTemplate;

import java.util.HashMap;
import java.util.Map;

public class DockerSystem {

    private final String url;

    public DockerSystem(String url) {
        this.url = url;
    }

    public DockerAuthResult auth(String userName, String passWord, String serverAddress) {
        final String uri = url + "/auth";
        RestTemplate restTemplate = new RestTemplate();
        Map<String, Object> request = new HashMap<String, Object>(){{
            this.put("username", userName);
            this.put("password", passWord);
            this.put("serveraddress", serverAddress);
        }};
        return restTemplate.postForObject(uri, request, DockerAuthResult.class);
    }

    public DockerInfoResult info() {
        final String uri = url + "/info";
        RestTemplate restTemplate = new RestTemplate();
        return restTemplate.getForObject(uri, DockerInfoResult.class);
    }

    public DockerVersionResult version() {
        final String uri = url + "/version";
        RestTemplate restTemplate = new RestTemplate();
        return restTemplate.getForObject(uri, DockerVersionResult.class);
    }

    public String ping() {
        final String uri = url + "/_ping";
        RestTemplate restTemplate = new RestTemplate();
        return restTemplate.getForObject(uri, String.class);
    }

    public DockerEventResult event() {
        final String uri = url + "/events";
        RestTemplate restTemplate = new RestTemplate();
        return restTemplate.getForObject(uri, DockerEventResult.class);
    }

    public DockerDfResult df() {
        final String uri = url + "/system/df";
        RestTemplate restTemplate = new RestTemplate();
        return restTemplate.getForObject(uri, DockerDfResult.class);
    }
}


